
LOCAL_PATH:=${PWD}
OUTPUT=${LOCAL_PATH}/output
DEMO=${LOCAL_PATH}/demo
SRC:=${LOCAL_PATH}/source/src/*.c
INCLUDE:=${LOCAL_PATH}/source/include
EIGEN_IN:=/usr/local/include/eigen3

HELLO_SRC:=${LOCAL_PATH}/source/src/hello.c
HELLO_H:=${LOCAL_PATH}/source/include/

LIBUSE_SRC:=${DEMO}/libuse.c
LIBUSE_SRC+=${SRC}

CPP:=g++
CC:=gcc
AR:=ar
cflags:=-std=c++11 -pthread
cflags_cv:=-lGL -lGLU -lglut -lm `pkg-config --cflags --libs opencv4`
cflags_error:=-pedantic -Wall -Werror

build:
	mkdir -p ${OUTPUT}

	$(CPP) ${DEMO}/cerr_test.cpp ${cflags} -o ${OUTPUT}/cerr_test

	$(CPP) ${DEMO}/pdcm_test.cpp ${cflags_cv} -o ${OUTPUT}/pdcm_test

	$(CPP) ${DEMO}/coord_cvt.cpp ${cflags_cv} -o ${OUTPUT}/coord_cvt

	${CPP} ${DEMO}/csv_test.cpp -o ${OUTPUT}/csv_test

	$(CPP) ${DEMO}/vector_test.cpp -o ${OUTPUT}/vector_test

	$(CPP) ${DEMO}/template_test.cpp -o ${OUTPUT}/template_test

	$(CC) ${LIBUSE_SRC} -I${INCLUDE} -o ${OUTPUT}/libuse

preprocessing:
	$(CC) -E ${HELLO_SRC} -I${HELLO_H} -o ${OUTPUT}/hello.i
compilation:
	$(CC) -S ${OUTPUT}/hello.i -o ${OUTPUT}/hello.s
assembly:
	# $(CC) -fPIC -c ${HELLO_SRC} -o ${OUTPUT}/hello.o
	$(CC) -c ${OUTPUT}/hello.s -o ${OUTPUT}/hello.o
generate_libs_dyn:
	${AR} -crv ${OUTPUT}/libhello.so ${OUTPUT}/hello.o 
generate_libs_sta:
	${AR} -crv ${OUTPUT}/libhello.a ${OUTPUT}/hello.o
linking_sta:
	$(CC) ${DEMO}/libuse.c -static -I${HELLO_H} -L${OUTPUT} -lhello ${cflags_error} -o ${OUTPUT}/libuse_sta
linking_dyn:
	$(CC) ${DEMO}/libuse.c -I${HELLO_H} -L${OUTPUT}/. -lhello ${cflags_error} -o ${OUTPUT}/libuse_dyn 

clean:
	rm -rf ${OUTPUT}/
run_vector:
	${OUTPUT}/vector_test
run_template:
	${OUTPUT}/template_test
run_libuse:
	${OUTPUT}/libuse
run_libuse_sta:
	${OUTPUT}/libuse_sta
run_libuse_dyn:
	${OUTPUT}/libuse_dyn
run_pfun:
	${OUTPUT}/pfun

test_libuse_sta:
	mkdir -p ${OUTPUT}
	make preprocessing
	make compilation
	make assembly
	make generate_libs_sta
	make linking_sta
	make run_libuse_sta
test_libuse_dyn:
	mkdir -p ${OUTPUT}
	make preprocessing
	make compilation
	make assembly
	make generate_libs_dyn
	make linking_dyn
	make run_libuse_dyn
test_smart_ptr:
	mkdir -p ${OUTPUT}
	${CPP} ${DEMO}/smart_ptr.cpp -std=c++98 ${cflags_error} -o ${OUTPUT}/smart_ptr
	make run_smart_ptr
test_pfun:
	mkdir -p ${OUTPUT}
	${CC} ${DEMO}/pfun.c -o ${OUTPUT}/pfun
	make run_pfun
test_big_little_endian:
	mkdir -p ${OUTPUT}
	${CC} ${DEMO}/big_little_endian.c -o ${OUTPUT}/big_little_endian
	${OUTPUT}/big_little_endian
test_fix_func:
	mkdir -p ${OUTPUT}
	${CC} ${DEMO}/fix_func.c ${DEMO}/func.c -pthread -o ${OUTPUT}/fix_func
	${OUTPUT}/fix_func
test_bit_reverse:
	mkdir -p ${OUTPUT}
	${CC} ${DEMO}/bit_reverse.c -o ${OUTPUT}/bit_reverse
	${OUTPUT}/bit_reverse
test_str_reverse:
	mkdir -p ${OUTPUT}
	${CC} ${DEMO}/str_reverse.c -o ${OUTPUT}/str_reverse
	${OUTPUT}/str_reverse
test_mergeList:
	mkdir -p ${OUTPUT}
	${CC} ${DEMO}/mergeList.c -o ${OUTPUT}/mergeList
	${OUTPUT}/mergeList
test_mutex:
	mkdir -p ${OUTPUT}
	$(CPP) ${DEMO}/mutex_test.cpp ${cflags} -o ${OUTPUT}/mutex_test
	${OUTPUT}/mutex_test
test_search_matrix:
	mkdir -p ${OUTPUT}
	${CC} ${DEMO}/search_2matrix.c -o ${OUTPUT}/search_2matrix
	${OUTPUT}/search_2matrix
test_auto_ptr:
	mkdir -p ${OUTPUT}
	${CPP} ${DEMO}/smart_ptr/auto_ptr.cpp -std=c++98 ${cflags_error} -o ${OUTPUT}/auto_ptr
	${OUTPUT}/auto_ptr
test_unique_ptr:
	mkdir -p ${OUTPUT}
	${CPP} ${DEMO}/smart_ptr/unique_ptr.cpp -std=c++11 -o ${OUTPUT}/unique_ptr
	${OUTPUT}/unique_ptr
test_shared_ptr:
	mkdir -p ${OUTPUT}
	${CPP} ${DEMO}/smart_ptr/shared_ptr.cpp -std=c++11 -o ${OUTPUT}/shared_ptr
	${OUTPUT}/shared_ptr
test_weak_ptr:
	mkdir -p ${OUTPUT}
	${CPP} ${DEMO}/smart_ptr/weak_ptr.cpp -o ${OUTPUT}/weak_ptr
	${OUTPUT}/weak_ptr
test_const_ptr:
	mkdir -p ${OUTPUT}
	${CPP} ${DEMO}/smart_ptr/const_ptr.cpp -o ${OUTPUT}/const_ptr
	${OUTPUT}/const_ptr
test_quote:
	mkdir -p ${OUTPUT}
	${CPP} ${DEMO}/quote.cpp -o ${OUTPUT}/quote
	${OUTPUT}/quote
test_quickSort:
	mkdir -p ${OUTPUT}
	${CPP} ${DEMO}/vslam_lec/quickSort.cpp -o ${OUTPUT}/quickSort
	${OUTPUT}/quickSort
test_bubbleSort:
	mkdir -p ${OUTPUT}
	${CPP} ${DEMO}/vslam_lec/bubbleSort.cpp -o ${OUTPUT}/bubbleSort
	${OUTPUT}/bubbleSort
test_new_feature:
	mkdir -p ${OUTPUT}
	${CPP} ${DEMO}/vslam_lec/new_feature_cpp.cpp -o ${OUTPUT}/new_feature
	${OUTPUT}/new_feature
test_hpc_multi_thread:
	mkdir -p ${OUTPUT}
	${CC} ${DEMO}/hpc/multi_thread.c -pthread -o ${OUTPUT}/multi_thread
	${OUTPUT}/multi_thread
test_transform:
	mkdir -p ${OUTPUT}
	${CPP} ${DEMO}/vslam_lec/transform.cpp -I${EIGEN_IN} -o ${OUTPUT}/transform
	${OUTPUT}/transform
test_operator_convolution:
	mkdir -p ${OUTPUT}
	${CPP} ${DEMO}/operator/convolution.cpp ${cflags} ${cflags_cv} -o ${OUTPUT}/convolution
	${OUTPUT}/convolution
test_mode:
	mkdir -p ${OUTPUT}
	${CC} ${DEMO}/mode.c -o ${OUTPUT}/mode
	${OUTPUT}/mode
test_image_process:
	mkdir -p ${OUTPUT}
	$(CPP) ${DEMO}/img_process.cpp ${cflags_cv} -o ${OUTPUT}/img_process
	${OUTPUT}/img_process
test_neuralNet:
	mkdir -p ${OUTPUT}
	$(CC) ${DEMO}/operator/neuralNet.c -o ${OUTPUT}/neuralNet
	${OUTPUT}/neuralNet
test_newton:
	mkdir -p ${OUTPUT}
	$(CC) ${DEMO}/newton_itr.c -o ${OUTPUT}/newton_itr
	${OUTPUT}/newton_itr
test_day1:
	mkdir -p ${OUTPUT}
	$(CC) ${DEMO}/algo_code/day1.c ${cflags_error} -o ${OUTPUT}/day1
	${OUTPUT}/day1
test_day2:
	mkdir -p ${OUTPUT}
	$(CC) ${DEMO}/algo_code/day2.c ${cflags_error} -o ${OUTPUT}/day2
	${OUTPUT}/day2
test_day3:
	mkdir -p ${OUTPUT}
	$(CC) ${DEMO}/algo_code/day3.c ${cflags_error} -o ${OUTPUT}/day3
	${OUTPUT}/day3
test_day4:
	mkdir -p ${OUTPUT}
	$(CPP) ${DEMO}/algo_code/day4.cpp -o ${OUTPUT}/day4
	${OUTPUT}/day4
test_day5:
	mkdir -p ${OUTPUT}
	$(CPP) ${DEMO}/algo_code/day5.cpp -o ${OUTPUT}/day5
	${OUTPUT}/day5
test_day6:
	mkdir -p ${OUTPUT}
	$(CPP) ${DEMO}/algo_code/day6.cpp -o ${OUTPUT}/day6
	${OUTPUT}/day6
test_day7:
	mkdir -p ${OUTPUT}
	$(CC) -S ${DEMO}/algo_code/day7.c -I${INCLUDE} ${cflags_error} -O3 -o ${OUTPUT}/day7.s
	$(CC) ${DEMO}/algo_code/day7.c -I${INCLUDE} ${cflags_error} -O3 -o ${OUTPUT}/day7
	${OUTPUT}/day7
test_day8:
	mkdir -p ${OUTPUT}
	$(CPP) ${DEMO}/algo_code/day8.cpp -o ${OUTPUT}/day8
	${OUTPUT}/day8
test_day9:
	mkdir -p ${OUTPUT}
	$(CC) -g ${DEMO}/algo_code/day9.c -o ${OUTPUT}/day9
	valgrind --leak-check=full ${OUTPUT}/day9
test_day10:
	mkdir -p ${OUTPUT}
	$(CPP) -g ${DEMO}/algo_code/day10.cpp -o ${OUTPUT}/day10
	${OUTPUT}/day10
test_day11:
	mkdir -p ${OUTPUT}
	$(CPP) -g ${DEMO}/algo_code/day11.cpp -o ${OUTPUT}/day11
	# valgrind --leak-check=full ${OUTPUT}/day11
	${OUTPUT}/day11
test_day12:
	mkdir -p ${OUTPUT}
	$(CPP) -g ${DEMO}/algo_code/day12.cpp -o ${OUTPUT}/day12
	# valgrind --leak-check=full ${OUTPUT}/day12
	${OUTPUT}/day12
test_day13:
	mkdir -p ${OUTPUT}
	$(CPP) -g ${DEMO}/algo_code/day13.cpp -o ${OUTPUT}/day13
	# valgrind --leak-check=full ${OUTPUT}/day13
	${OUTPUT}/day13
test_day14:
	mkdir -p ${OUTPUT}
	$(CPP) ${DEMO}/algo_code/day14.cpp -o ${OUTPUT}/day14
	${OUTPUT}/day14
test_day15:
	mkdir -p ${OUTPUT}
	$(CPP) ${DEMO}/algo_code/day15.cpp -o ${OUTPUT}/day15
	${OUTPUT}/day15
test_day16:
	mkdir -p ${OUTPUT}
	$(CPP) ${DEMO}/algo_code/day16.cpp -I${INCLUDE} -o ${OUTPUT}/day16
	${OUTPUT}/day16
test_day17:
	mkdir -p ${OUTPUT}
	$(CPP) ${DEMO}/algo_code/day17.cpp -I${INCLUDE} -lpthread -o ${OUTPUT}/day17
	${OUTPUT}/day17
test_day18:
	mkdir -p ${OUTPUT}
	$(CPP) ${DEMO}/algo_code/day18.cpp -I${INCLUDE} -o ${OUTPUT}/day18
	${OUTPUT}/day18
test_day19:
	mkdir -p ${OUTPUT}
	$(CPP) ${DEMO}/algo_code/day19.cpp -I${INCLUDE} -o ${OUTPUT}/day19
	${OUTPUT}/day19
test_day20:
	mkdir -p ${OUTPUT}
	$(CPP) ${DEMO}/algo_code/day20.cpp -I${INCLUDE} -o ${OUTPUT}/day20
	${OUTPUT}/day20
test_day21:
	mkdir -p ${OUTPUT}
	$(CPP) -g ${DEMO}/algo_code/day21.cpp -I${INCLUDE} -o ${OUTPUT}/day21
	${OUTPUT}/day21
test_gdb21:
	gdb ${OUTPUT}/day21
test_day22:
	mkdir -p ${OUTPUT}
	$(CPP) ${DEMO}/algo_code/day22.cpp -I${INCLUDE} -o ${OUTPUT}/day22
	${OUTPUT}/day22
test_day23:
	mkdir -p ${OUTPUT}
	$(CPP) ${DEMO}/algo_code/day23.cpp -I${INCLUDE} -o ${OUTPUT}/day23
	${OUTPUT}/day23
test_day24:
	mkdir -p ${OUTPUT}
	$(CPP) ${DEMO}/algo_code/day24.cpp -I${INCLUDE} -o ${OUTPUT}/day24
	${OUTPUT}/day24
test_day25:
	mkdir -p ${OUTPUT}
	$(CPP) ${DEMO}/algo_code/day25.cpp -I${INCLUDE} -o ${OUTPUT}/day25
	${OUTPUT}/day25
test_day26:
	mkdir -p ${OUTPUT}
	$(CPP) ${DEMO}/algo_code/day26.cpp -I${INCLUDE} -lpthread -o ${OUTPUT}/day26
	${OUTPUT}/day26
test_day27:
	mkdir -p ${OUTPUT}
	$(CPP) ${DEMO}/algo_code/day27.cpp -I${INCLUDE} -lpthread -o ${OUTPUT}/day27
	${OUTPUT}/day27
test_day28:
	mkdir -p ${OUTPUT}
	$(CPP) ${DEMO}/algo_code/day28.cpp -I${INCLUDE} -lpthread -o ${OUTPUT}/day28
	${OUTPUT}/day28
test_day29:
	mkdir -p ${OUTPUT}
	$(CPP) ${DEMO}/algo_code/day29.cpp -I${INCLUDE} -lpthread -o ${OUTPUT}/day29
	${OUTPUT}/day29
test_day30:
	mkdir -p ${OUTPUT}
	$(CC) ${DEMO}/algo_code/day30.c -I${INCLUDE} -fopenmp -o ${OUTPUT}/day30
	${OUTPUT}/day30
test_day31:
	mkdir -p ${OUTPUT}
	$(CPP) ${DEMO}/algo_code/day31.cpp -I${INCLUDE} -o ${OUTPUT}/day31
	${OUTPUT}/day31
test_day32:
	mkdir -p ${OUTPUT}
	$(CPP) ${DEMO}/algo_code/day32.cpp -I${INCLUDE} -lpthread -o ${OUTPUT}/day32
	${OUTPUT}/day32
test_day33:
	mkdir -p ${OUTPUT}
	$(CPP) ${DEMO}/algo_code/day33.c -I${INCLUDE} -lpthread -o ${OUTPUT}/day33
	${OUTPUT}/day33
test_day34:
	mkdir -p ${OUTPUT}
	$(CPP) ${DEMO}/algo_code/day34.c -I${INCLUDE} -lpthread -lcomdlg32 -o ${OUTPUT}/day34
	${OUTPUT}/day34
test_day35:
	mkdir -p ${OUTPUT}
	$(CPP) ${DEMO}/algo_code/day35.cpp -I${INCLUDE} -lpthread -lsfml-graphics -lsfml-window -lsfml-system -lcomdlg32 -o ${OUTPUT}/day35
	${OUTPUT}/day35














test_acwing_day1:
	mkdir -p ${OUTPUT}
	$(CPP) ${DEMO}/acwing/day1.cpp -I${INCLUDE} -lpthread -o ${OUTPUT}/day1
	${OUTPUT}/day1

	
	
